<?php

namespace App\Http\Controllers\Admin;

use App\Services\Wxtj\WxtjUser;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

/**
 * 微信用户统计
 * @package App\Http\Controllers\Admin
 */
class WxtjUserController extends BaseWxController
{
    /**
     * 用户增减数据
     * @param Request $request
     */
    public function summary(Request $request, WxtjUser $wxtjUser)
    {
        if ($request->ajax()) {
            $data = formatChartDataByDate();
            return $data;
            //关注渠道
            $query = \App\Models\WxtjUserSummary::select('ref_date','new_user','cancel_user');
            //查询指定微信应用
            $curWxMp = \Auth::user()->getWxMpCurrent();
            $appid = $curWxMp ? $curWxMp['appid'] : '';
            $query->where('appid', $appid);
            //用户来源
            $userResource = $request->input('user_resource', 0);
            if ($userResource) {
                $query->where('user_resource', $userResource);
            }
            //DB::table('test')->paginate();
            $rows = $query->get();
            if ($rows) {
                /*foreach ($rows as $k => $v) {
                    $v['subscribe_scene_name'] = $v->subscribe_scene_name;
                    $v['sex_name'] = $v->sex_name;
                    $v['tagid_list'] = (array) $v->tagid_list;
                    $v['tagname_list'] = $v->tagname_list;
                    $rows[$k] = $v;
                }*/
            }
            return $rows;
        }
        $this->viewData['userSourceTypeList'] = $wxtjUser->getUserSourceTypeList();
        return view('admin.wxtjuser.summary', $this->viewData);
    }

    /**
     * 累计用户数据
     * @param Request $request
     */
    public function cumulate(Request $request)
    {

    }
}
